package StackOrQueue;

import java.util.Stack;

    //leetcode submit region begin(Prohibit modification and deletion)
class MinStackWithoutHelper {

    Stack<int[]> stack;

    public MinStackWithoutHelper() {
        stack = new Stack<>();
    }

    public void push(int val) {
        if(stack.empty()){
            //初始空时，当前最小值就是本身
            stack.push(new int[]{val,val});
        }else{
            //不为空时，取当前最小值存入
            int min = Math.min(val, stack.peek()[1]);
            stack.push(new int[]{val,min});
        }

    }

    public void pop() {
        if(!stack.empty()){
            //直接弹出
            stack.pop();
        }

    }

    public int top() {
        //直接返回，stack的栈顶的下标0
        return stack.peek()[0];
    }

    public int getMin() {
        //直接返回栈顶下标1的值
        return stack.peek()[1];
    }
}
